import axios from 'axios'
import baseUrl from './API.js'
import { Message } from 'element-ui';

const baseURL = baseUrl

const service = axios.create({
    baseURL: baseURL,
    timeout: 1000 * 60 * 60
})

axios.interceptors.request.use(function (config) {
  // Do something before request is sent
  return config;
}, function (error) {
  Message.error("服务端似乎没有开启哦")
  return Promise.reject(error);
});

service.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response.data;
  }, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    Message.error("服务端似乎出现了异常")
    return Promise.reject(error);
  });

service.defaults.withCredentials = true

export default service